﻿namespace Budgetsch.WP7.View
{
    using System;

    using Budgetsch.WP7.Navigation;
    using Budgetsch.WP7.ViewModel;

    using GalaSoft.MvvmLight.Ioc;
    using GalaSoft.MvvmLight.Messaging;

    /// <summary>
    /// Description for CommentWriterView.
    /// </summary>
    public partial class CommentWriterView
    {
        private string type;
        private int itemId;
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            type = NavigationContext.QueryString["type"];
            itemId = Int32.Parse(NavigationContext.QueryString["itemid"]);
        }

        /// <summary>
        /// Initializes a new instance of the CommentWriterView class.
        /// </summary>
        public CommentWriterView()
        {
            InitializeComponent();
        }

        private void CommentSendAppButton_Click(object sender, EventArgs e)
        {
            SimpleIoc.Default.GetInstance<CommentWriterViewModel>();
            switch (type)
            {
                case "income":
                    Messenger.Default.Send(new CreateNewIncomeCommentMessage { Message = CommentBox.Text, ItemId = itemId });
                    break;
                case "cost":
                    Messenger.Default.Send(new CreateNewCostCommentMessage { Message = CommentBox.Text, ItemId = itemId });
                    break;
                case "saving":
                    Messenger.Default.Send(new CreateNewSavingCommentMessage { Message = CommentBox.Text, ItemId = itemId });
                    break;
            }
        }
    }
}